package cn.wolfcode.transfer.domain;

import cn.hutool.core.date.BetweenFormater;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.unit.DataUnit;
import cn.wolfcode.transfer.util.LevelUtil;
import com.alibaba.fastjson.JSON;

import java.net.PortUnreachableException;
import java.util.Date;
import java.util.HashMap;

public class Notice {
    /** 主键*/
    private Long id;

    /** 标题*/
    private String headline;

    /** 创建人id*/
    private Employee creator;

    /** 创建时间*/
    private Date creationTime;

    /** 紧急级别*/
    private Integer level = 2;

    /** 是否已读*/
    private boolean markRead = false;

    /** 是否发布*/
    private boolean publishStatus = false;

    private Date publishTime ;

    public Date getPublishTime() {
        return publishTime;
    }
    public String getIntervalTime() {
        if (this.publishTime==null){
            return null;
        }
        String s = DateUtil.formatBetween(this.publishTime, new Date(), BetweenFormater.Level.MINUTE);
        return s;
    }

    public void setPublishTime(Date publishTime) {
        this.publishTime = publishTime;
    }

    private String text;
    public String levelName(){
        return LevelUtil.forLevelValue(this.level);
    }
    public String toJson(){
        HashMap<String,Object> map =new HashMap();
        map.put("id",id);
        map.put("headline",headline);
        map.put("level", level);
        map.put("MyText",text);
        return JSON.toJSONString(map);
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getHeadline() {
        return headline;
    }

    public void setHeadline(String headline) {
        this.headline = headline;
    }

    public Employee getCreator() {
        return creator;
    }

    public void setCreator(Employee creator) {
        this.creator = creator;
    }

    public Date getCreationTime() {
        return creationTime;
    }

    public void setCreationTime(Date creationTime) {
        this.creationTime = creationTime;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public boolean isMarkRead() {
        return markRead;
    }

    public void setMarkRead(boolean markRead) {
        this.markRead = markRead;
    }

    public boolean isPublishStatus() {
        return publishStatus;
    }

    public void setPublishStatus(boolean publishStatus) {
        this.publishStatus = publishStatus;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }
}